package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Shop;

public class ShopDAOImpl extends BaseHibernateDAOImpl<Shop> implements ShopDAO {

	public Shop getShopByShopID(String shopID) {
		Shop shop;
		try {
			shop = (Shop) getSession().get(Shop.class, shopID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return shop;
	}

	@SuppressWarnings("unchecked")
	public List<Shop> getAllShop() {
		List<Shop> shops;
		try {
			Query query = getSession().getNamedQuery("AllShopQuery");
			shops = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return shops;
	}

	@SuppressWarnings("unchecked")
	public List<Shop> getAllShopByPage(int currentPage, int lineSize) {
		List<Shop> shops;
		try {
			Query query = getSession().getNamedQuery("AllShopByPageQuery");
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			shops = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return shops;
	}
	
	@SuppressWarnings("unchecked")
	public List<Shop> getAllShopByShopType(String shopType) {
		List<Shop> shops;
		try {
			Query query = getSession().getNamedQuery("AllShopByShopTypeQuery");
			query.setString("shopType", shopType);
			shops = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return shops;
	}


}
